package alo.p19;

/**
 * @ClassName Floyd
 * @Description 任意两点之间的最短路径
 * @Author Fanxc
 * @DATE 2021/3/15 19:56
 * @Version 1.0
 */
public class Floyd {
    void floyd(int[][] A,int[][] C,int n){
        //初始化
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                A[i][j]=C[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            A[i][i]=0;
        }
        //Floyd算法
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (A[i][k]+A[k][j]<A[i][j]){
                        A[i][j]=A[i][k]+A[k][j];
                    }
                }
            }
        }
    }
}
